<?php
function get_group_member($userid){
	$query="SELECT USERID FROM user WHERE USERGROUP=(SELECT USERGROUP FROM user WHERE USERID=$userid)";
	//$query="SELECT USERID FROM user WHERE USERGROUP=(SELECT USERGROUP FROM user WHERE USERID=$userid) UNION ALL SELECT USERGROUP AS USERID FROM user WHERE USERID=$userid";
	$result=mysql_query($query);
	return $result;
}
function get_group($userid){
	$query="SELECT USERGROUP FROM user WHERE USERID=$userid";
	$result=mysql_query($query);
	return $result;
}
function get_username($userid){
	$query="SELECT USERNAME FROM user WHERE USERID=$userid";
	$result=mysql_query($query);
	$row=mysql_fetch_array($result);
	return $row['USERNAME'];
}
function get_questions_list($author,$str_sql){
	$query="SELECT * FROM qa WHERE AUTHOR IN($str_sql) ORDER BY DATETIME DESC";
	$result=mysql_query($query);
	return $result;
}
function get_comments_num($qaid){
	$query="SELECT COUNT(*) AS commentsnum FROM qacomment WHERE TITLEID=".$qaid;
	$result=mysql_query($query);
	$row=mysql_fetch_array($result);
	return $row['commentsnum'];
}
function get_questions_list_a(){
	$query="SELECT * FROM qa ORDER BY DATETIME DESC";
	$result=mysql_query($query);
	return $result;
}
function save_question($questiontitle,$questioncontent,$author,$questiontype,$ipaddress){
	$query="INSERT INTO qa(TITLE,CONTENT,AUTHOR,TYPE,IPADDRESS) VALUES('$questiontitle','$questioncontent',$author,$questiontype,'$ipaddress')";
	mysql_query($query);
}
function save_question_comment($titleid,$comment,$author){
	$query="INSERT INTO qacomment(CONTENT,TITLEID,AUTHOR) VALUES('$comment',$titleid,$author)";
	mysql_query($query);
}
function check_deleting_questions($titleid,$author){
	$query="SELECT * FROM qa WHERE Id=$titleid";
	$result=mysql_query($query);
	return $result;
}
function del_questions($titleid){
	$query="DELETE FROM qa WHERE Id=$titleid";
	mysql_query($query);
	$query="DELETE FROM qacomment WHERE TITLEID=$titleid";
	mysql_query($query);
}
function get_question_detail($id){
	$query="SELECT 
			qa.TITLE,
			qa.CONTENT as QCONTENT,
			qa.AUTHOR as QAUTHOR,
			qa.DATETIME as QTIME,
			qa.TYPE,
			qacomment.CONTENT AS CCONTENT,
			qacomment.DATETIME as CTIME,
			qacomment.AUTHOR AS CAUTHOR 
			FROM qa 
			LEFT JOIN qacomment 
			ON qacomment.TITLEID=$id
			WHERE  qa.Id=$id
			";
	$result=mysql_query($query);
	return $result;
}
function get_questions_index(){
	$query="SELECT * FROM qa WHERE TYPE=".PUBLICQUESTIONCODE." ORDER BY DATETIME DESC LIMIT 0,8";
	$result=mysql_query($query);
	return $result;
}
?>